package com.exd.flink.source;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;

/**
 * 描述: 数据源公共类
 * 创建人: 赵兴炎
 * 日期: 2022年9月13日
 */
public class StreamSourceInter {
	
	
	/**
	 * 获取kafka数据源的数据
	 */
	public static DataStreamSource<String> kafkaSource(StreamExecutionEnvironment streamExecutionEnvironment) {
		FlinkKafkaConsumer<String> flinkKafkaConsumer = KafkaSource.getFlinkKafkaConsumer();
		return streamExecutionEnvironment.addSource(flinkKafkaConsumer);
	}
	
	/**
	 * 获取本地文件数据源的代码
	 */
	public static DataStreamSource<String> localFileSource(StreamExecutionEnvironment streamExecutionEnvironment) {
		return streamExecutionEnvironment.readTextFile("D:\\\\vdata2.txt");
	}
	
	/**
	 * 获取本地文件数据源的代码
	 */
	public static DataStreamSource<String> localFileSource(String filePath,StreamExecutionEnvironment streamExecutionEnvironment) {
		return streamExecutionEnvironment.readTextFile(filePath);
	}

}
